package com.nondo.rdp.finance.repository.course;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.course.CourseClassify;

public interface CourseClassifyRepository extends JpaRepository<CourseClassify, Long>,
		JpaSpecificationExecutor<CourseClassify> {
	@Query("select a from CourseClassify a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	Optional<CourseClassify> findOne(@Param("id") int id);

	@Modifying
	@Query("update CourseClassify set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
	void deleteById(Long id);

	@SuppressWarnings("unchecked")
	CourseClassify save(CourseClassify courseClassify);

	@Query("select a from CourseClassify a where a.name=:name and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	CourseClassify findByName(@Param("name") String name);

	@Query("select a from CourseClassify a where a.pid=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	List<CourseClassify> findByPid(@Param("id")Long id);

}
